<?php
class Modelbcs extends ModelBase1 {
	
	protected $tablename = '';
	
	
	private $data=null;
	
	/**
	 *
	 * @var CDbConnection
	 */
	function init(){
		$this->baseurl=$_SERVER['SERVER_NAME']."?path=services&action=bcs";
		#echo $this->baseurl=urlforservice('services/bcs/checkLogin');exit;
	}
	
	public function checkuser($phone,$pwd){
		
		$methodname = "checkLogin";
		$this->data['phone'] = filter::quote($phone,'int');
		$this->data['pwd']   = filter::quote($pwd);
		
		
		try {
			$result = requestserver($this->baseurl."&method=".$methodname,$this->data,'post');
			$result = requestserver("http://58.254.177.56:8089/bcs/tservice/checkLogin", $this->data,'post');
			return json_decode($result);
		}catch(Exception $exception){
			dumpe($exception);
		}
		return null;
		
	}
	
	public function getuserinfo($iswel=0){
		
		$user = cache::getdata ( 'user', 'cookie' );
		
		 
		 $methodname = "queryCustomer";
		 if(isset($user) && is_numeric($user)){
		 	$this->data['VhlCustomerVo']['vhlCustomer']['id']=$user;
		 	
		 	try {
		 		$result = requestserver($this->baseurl."&method=".$methodname,array('data'=>json_encode($this->data)),'post');
				
		 		$result = json_decode($result,1);
		 		
		 		if($iswel==1){
		 			return $result[0]['resultVo'];
		 		}else{
		 			return $result[0]['resultVo'];
		 		}
		 		
		 	}catch(Exception $exception){
		 		dumpe($exception);
		 	}
		 }
		
		 return null;
		
	}
	
	public function saveuserinfo($userinfo){
		
		$result = null;
		global $_SGLOBAL;
		$user = $_SGLOBAL['uid'];
		$methodname="updateCustomer";
		
		
		if(isset($user)){
			$userinfo['id'] = $user;
			$this->data['customer']=$userinfo;
			if(isset($userinfo['contactPhone']) && isset($userinfo["contact"])){
				
				try {
					$result = requestserver($this->baseurl."&method=".$methodname,array('data'=>json_encode($this->data)),'post');				
					
				}catch(Exception $exception){
					dumpe($exception);
				};
			}else{
				try {
					$result = requestserver($this->baseurl."&method=".$methodname,array('data'=>json_encode($this->data)),'post');					
					
				}catch(Exception $exception){
					dumpe($exception);
				};
			}
			
			$result = json_decode($result,1);
		
		}
		
		return $result;
	}
	
	public function getContractInfo(){
		global $_SGLOBAL;
		$methodname = "getContractInfo";
	
		if(isset($_SGLOBAL['vincode'])){
			$result = requestserver($this->baseurl."&method=".$methodname,array('vin'=>$_SGLOBAL['vincode']),'get');
			return $result;
		}
	}
	
	public function updatepin($pin){
		global $_SGLOBAL;
		$methodname = "updatePin";
	
		if(isset($_SGLOBAL['uid'])&&isset($pin)){
			$result = requestserver($this->baseurl."&method=".$methodname,array('userId'=>$_SGLOBAL['uid'],'pin'=>$pin),'get');
			return $result;
		}
	}
	
	
	
	

}
?>
